#ifndef CLIENTCOMMUNICATION_H
#define CLIENTCOMMUNICATION_H

#include <QObject>
#include <memory>
#include "client.h"
#include "system_input.h"



class QTcpSocket;
class QTimer;
class ClientCommunication :public Client
{
    Q_OBJECT
public:
    explicit ClientCommunication(const QString ip, const unsigned short port = 9999);
    ~ClientCommunication() override;

    //依赖注入
    void setEngine(SystemInput* input);

    void startScanServer();

    void onWritData(const QByteArray data) override;
signals:
    void sigStartTimer();

    void sigReadData(QByteArray data);

private slots:
    void onConnectServer() override;
    void onReadData() override;

    //在同一个线程中创建定时器，避免跨线程操作
    void onCreateTimer();

private:
    QTcpSocket* client_socket_;

    QTimer *monitor_connect_time_;

    std::unique_ptr<SystemInput> stystem_input_;
};

#endif // CLIENTCOMMUNICATION_H
